package com.xpgk.mvc.collection.collectionServicePart;

import java.text.NumberFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jfinal.log.Log;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.xpgk.annotation.Service;
import com.xpgk.constant.ConstantRender;
import com.xpgk.mvc.base.BaseService;
import com.xpgk.mvc.bentryRegister.Customer;
import com.xpgk.mvc.bentryRegister.CustomerDetail;
import com.xpgk.mvc.bentryRegister.CustomerHabit;
import com.xpgk.mvc.bentryRegister.CustomerProduct;
import com.xpgk.mvc.bentryRegister.CustomerProductSurplus;
import com.xpgk.mvc.bloseWeight.DelWeiTarget;
import com.xpgk.mvc.bloseWeight.DelWeiTargetSum;
import com.xpgk.mvc.codeSet.Code;
import com.xpgk.mvc.productOutin.ProductOutin;
import com.xpgk.mvc.productSet.Product;
import com.xpgk.mvc.productSet.ProductExperience;
import com.xpgk.mvc.productStock.ProductStock;
import com.xpgk.mvc.productStock.ProductStockInfo;
import com.xpgk.mvc.user.User;
import com.xpgk.tools.ToolRandoms;

@Service(name = CollecttionBinShopServiceService.serviceName)
public class CollecttionBinShopServiceService extends BaseService {
	@SuppressWarnings("unused")
	private static final Log log = Log.getLog(CollecttionBinShopServiceService.class);
	public static final String serviceName = "collecttionBinShopServiceService";
	
	/**塑形，获取服务部信息
	 * 
	 * @param customerIds
	 * @param curUserIds
	 * @return
	 */
	public List<Map> getPartInfo(String customerIds, String curUserIds) {
		List<Map> partInfoList = new ArrayList<>();
		// 获取服务部位
		List<Code> codeList = Code.cacheGetChild(Code.fwbw_ids);
		if (codeList != null && codeList.size() > 0) {
			for (int i = 0; i < codeList.size(); i++) {
				Map<String, String> map = new HashMap<>();
				map.put("positionIds", codeList.get(i).getStr(Code.column_ids));
				map.put("position", codeList.get(i).getStr(Code.column_name));
				map.put("userids", curUserIds);
				map.put("name", User.cacheGetByUserId(curUserIds).getStr(User.column_name));
				String cusprosql = getSqlMy(CustomerProduct.sqlId_selByCusAndUseIdsAndPartIds);
				List<CustomerProduct> cpList = CustomerProduct.dao.find(cusprosql, Code.cpytFw_ids, customerIds,
						codeList.get(i).getStr(Code.column_ids));
				if (cpList != null && cpList.size() > 0) {
					for (int j = 0; j < cpList.size(); j++) {
						map.put(cpList.get(j).getStr(Product.column_ids), cpList.get(j).getStr(Product.column_ids));
						map.put("use_" + cpList.get(j).getStr(Product.column_ids),
								cpList.get(j).getFloat(ProductExperience.column_experience).toString());
						map.put("surplus_" + cpList.get(j).getStr(Product.column_ids),
								cpList.get(j).getFloat(CustomerProduct.column_totalExperience).toString());
					}
				}
				partInfoList.add(map);
			}

		}

		return partInfoList;

	}

	/**
	 * 获取测量部位尺寸
	 * 
	 * @param customerIds
	 * @return
	 */
	public List<Map> getPartSizeInfo(String customerIds) {
		List<Map> partSizeInfoList = new ArrayList<>();
		// 获取服务部位
		List<Code> codeList = Code.cacheGetChild(Code.fwbw_ids);
		for(Code code:codeList)
		{
			List<Code> cList = Code.cacheGetChild(code.getStr(Code.column_ids));
			for(Code cc:cList){
				Map<String, String> map = new HashMap<>();
				map.put("positionIds", cc.getStr(Code.column_ids));
				map.put("position", cc.getStr(Code.column_name));
				List<CollecttionServicePartSize>  spsList=CollecttionServicePartSize.dao.getServicePartSize(customerIds,cc.getStr(Code.column_ids));
				if(spsList!=null &&  spsList.size()>0)
				{
					map.put("positionSize", spsList.get(0).getFloat(CollecttionServicePartSize.column_size).toString());
				}else
				{
					map.put("positionSize", "0");
				}
				partSizeInfoList.add(map);
			}
		}

		return partSizeInfoList;
	}

	/**
	 * 获取默认生活习惯
	 * 
	 * @param cusIds
	 * @param orgIds
	 * @return
	 */
	public CustomerHabit getCusHabit(String cusIds, String orgIds) {
		String servicesql = getSqlMy(CollecttionCustomerService.sqlId_selByCusAndOrg);
		List<CollecttionCustomerService> csList = CollecttionCustomerService.dao.find(servicesql, cusIds, orgIds);
		if (csList != null && csList.size() > 0) {
			Map<String, Object> param = new HashMap<String, Object>();
			param.put("column", CustomerHabit.column_serviceID);
			String sql = getSqlByBeetl(CustomerHabit.sqlId_column, param);
			CustomerHabit ch = CustomerHabit.dao.findFirst(sql, csList.get(0).getStr(CollecttionCustomerService.column_ids));
			if (ch != null) {
				return ch;
			} else {
				return null;
			}

		} else {
			return null;
		}
	}

	/**
	 * 保存服务和生活习惯
	 * 
	 */
	public String saveInfo(Customer c, CustomerHabit ch, CollecttionCustomerService cs, String orgIds, String userIds,
			List<CollecttionServicePartSize> spsList, List<CollecttionServiceShaping> ssList, List<CustomerProduct> cpList,
			String plaster_ids) {
		String msg = ConstantRender.render_success_code; 
		
		CustomerDetail cd = c.getCustomerDetail();
		SimpleDateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd");
		String gxsj = "%" + dateFormater.format(new Date()) + "%";
		// 保存服务记录
		cs.set(CollecttionCustomerService.column_organids, orgIds)
				.set(CollecttionCustomerService.column_customerID, c.getStr(Customer.column_ids))
				.set(CollecttionCustomerService.column_userID, userIds)
				.set(CollecttionCustomerService.column_lastWeight, cd.getFloat(CustomerDetail.column_nowWeight))
				.set(CollecttionCustomerService.column_createDate, new Date());
		if (!cs.save()) {
			log.debug("保存服务记录失败");
			throw new RuntimeException("保存服务记录失败!");
		}
		if (cs.getStr(CollecttionCustomerService.column_isPlaster).equals("1")) {
			String plaster[] = plaster_ids.split(",");
			for (int i = 0; i < plaster.length; i++) {
				if (plaster[i] != null && !plaster[i].equals("")) {
					Product p = Product.dao.findById(plaster[i]);
					String pstSql = getSqlMy(ProductStock.sqlId_selPSByOidsAndPids);
					ProductStock pst = ProductStock.dao.findFirst(pstSql, orgIds, p.getStr(Product.column_ids));
					if (pst != null && pst.getFloat(ProductStock.column_num) >= 1) 
					{
						//保存药贴出库记录
						ProductOutin  po = new  ProductOutin();
						po.set(ProductOutin.column_ids, ToolRandoms.getUuid(true))
							.set(ProductOutin.column_organIds, orgIds)
							.set(ProductOutin.column_typeIds, p.getStr(Product.column_typeIds))
							.set(ProductOutin.column_productIds, p.getStr(Product.column_ids))
							.set(ProductOutin.column_number, 1)
							.set(ProductOutin.column_price, 0)
							.set(ProductOutin.column_date, new Date())
							.set(ProductOutin.column_style, "1")
							.set(ProductOutin.column_userIds, userIds)
							.set(ProductOutin.column_gxsj, new Date());
						if(!po.save())
						{
							log.debug("保存"+p.getStr(Product.column_name) +"出库记录失败！！");
							throw new RuntimeException("保存"+p.getStr(Product.column_name) + "出库记录失败！！");
						}
						// 更新产品库存
						
						// 根据日期和机构id,产品id查出当日是否有库存记录
						String pstInsql = getSqlMy(ProductStockInfo.sqlId_selByOidsAndPidsAndTime);
						ProductStockInfo psi = ProductStockInfo.dao.findFirst(pstInsql, orgIds,
								p.getStr(Product.column_ids), gxsj);
					
							float num1 = pst.getFloat(ProductStock.column_num) - 1;
							pst.set(ProductStock.column_num, num1).set(ProductStock.column_gxsj, new Date());
							if (!pst.update()) {
								log.debug("更新产品总库存失败");
								throw new RuntimeException("更新产品总库存失败!");
							}
							if (psi != null) {
								// 库存详细信息减少库存
								float num = psi.getFloat(ProductStockInfo.column_stock) - 1;
								psi.set(ProductStockInfo.column_stock, num)
										.set(ProductStockInfo.column_gxsj, new Date()).update();

							} else {
								ProductStockInfo psInfo = new ProductStockInfo();
								String psinfoids = ToolRandoms.getUuid(true);
								psInfo.set(ProductStockInfo.column_ids, psinfoids)
										.set(ProductStockInfo.column_organids, orgIds)
										.set(ProductStockInfo.column_productID, p.getStr(Product.column_ids))
										.set(ProductStockInfo.column_type, p.getStr(Product.column_typeIds))
										.set(ProductStockInfo.column_stock, pst.getFloat(ProductStock.column_num))
										.set(ProductStockInfo.column_gxsj, new Date());
								if (!psInfo.save()) {
									log.debug("保存产品库存记录失败！！");
									throw new RuntimeException("保存产品库存记录失败!");
								}
							}
						} else {
							log.debug(p.getStr(Product.column_name) + "库存不够，无法购买！！");
//							throw new RuntimeException(p.getStr(Product.column_name) + "库存不够，请先入库！！");
							msg=p.getStr(Product.column_name) + "库存不够，请先入库！！";
						}
				}
			}
		}
		//如果顾客为单疗程顾客，到店服务一次减少一次单疗程次数
		String  lcsql=getSqlMy(CustomerProduct.sqlId_selByCusAndType);
		CustomerProduct  lccp = CustomerProduct.dao.findFirst(lcsql,c.getStr(Customer.column_ids),Code.lc_ids,orgIds);
		if(lccp!=null && lccp.getStr("proUnits").equals(Code.dlc_units))
		{
			CustomerProduct  dlccp=CustomerProduct.dao.findById(lccp.getStr("ids"));
			dlccp.set(CustomerProduct.column_totalExperience, dlccp.getFloat(CustomerProduct.column_totalExperience)-1)
				.set(CustomerProduct.column_updateDate, new Date());
			if (!dlccp.update()) {
				log.debug("更新单疗程剩余失败");
				throw new RuntimeException("更新单疗程剩余失败!");
			}
		}
				
				
				
				
		
		// 保存塑形
		if (ssList.size() > 0) {
			for (CollecttionServiceShaping ss : ssList) {
				ss.set(CollecttionServiceShaping.column_serviceIds, cs.getStr(CollecttionCustomerService.column_ids))
						.set(CollecttionServiceShaping.column_customerIds, c.getStr(Customer.column_ids))
						.set(CollecttionServiceShaping.column_time, new Date());
				if (!ss.save()) {
					log.debug("保存塑形失败");
					throw new RuntimeException("保存塑形失败!");
				}
			}
			// 更新产品剩余量
			if (cpList.size() > 0) {
				for (CustomerProduct cp : cpList) {

					String cpSql = getSqlMy(CustomerProduct.sqlId_selByCusAndPro);
					CustomerProduct cuspro = CustomerProduct.dao.findFirst(cpSql, c.getStr(Customer.column_ids),
							cp.getStr(CustomerProduct.column_productID), orgIds);
					CustomerProductSurplus  cps=CustomerProductSurplus.dao.getCustomerProductSurplus(c.getStr(Customer.column_ids), cp.getStr(CustomerProduct.column_productID), orgIds, gxsj);
					if (cuspro != null) {
						double num=Math.ceil(cp.getFloat(CustomerProduct.column_totalExperience)/cuspro.getFloat(CustomerProduct.column_proExperience));
						cuspro.set(CustomerProduct.column_capacities, cp.getFloat(CustomerProduct.column_capacities))
								.set(CustomerProduct.column_totalExperience, cp.getFloat(CustomerProduct.column_totalExperience))
						        .set(CustomerProduct.column_count, num)
								.set(CustomerProduct.column_updateDate, new Date());
						if (!cuspro.update()) {
							log.debug("更新产品剩余量失败");
							throw new RuntimeException("更新产品剩余量失败!");
						}
						if(cps!=null)
						{
							//更新顾客产品剩余详细信息
							cps.set(CustomerProductSurplus.column_totalExperience, cp.getFloat(CustomerProduct.column_totalExperience))
							.set(CustomerProductSurplus.column_count, num)
							.set(CustomerProductSurplus.column_gxsj, new Date());
							if (!cps.update()) {
								log.debug("更新顾客产品明细失败！！");
								throw new RuntimeException("更新顾客产品明细失败!");
							}
						}else
						{
							//保存顾客产品剩余详细信息
							Product  p=Product.dao.findById(cp.getStr(CustomerProduct.column_productID));
							CustomerProductSurplus  cusprosur=new CustomerProductSurplus();
							cusprosur.set(CustomerProductSurplus.column_ids, ToolRandoms.getUuid(true))
									.set(CustomerProductSurplus.column_organIds, orgIds)
									.set(CustomerProductSurplus.column_customerIds, c.getStr(Customer.column_ids))
									.set(CustomerProductSurplus.column_productIds, cp.getStr(CustomerProduct.column_productID))
									.set(CustomerProductSurplus.column_count, num)
									.set(CustomerProductSurplus.column_proExperience,  p.getStr(Product.column_proExperience))
									.set(CustomerProductSurplus.column_totalExperience, cp.getFloat(CustomerProduct.column_totalExperience))
									.set(CustomerProductSurplus.column_gxsj, new Date());
							if (!cusprosur.save()) {
								log.debug("保存顾客产品明细失败！！");
								throw new RuntimeException("保存顾客产品明细失败!");
							}
						}
					}
				}
			}
		}

		
		// 保存尺寸
		if (spsList.size() > 0) {
			for (CollecttionServicePartSize sps : spsList) {
				sps.set(CollecttionServicePartSize.column_serviceIds, cs.getStr(CollecttionCustomerService.column_ids))
						.set(CollecttionServicePartSize.column_customerIds, c.getStr(Customer.column_ids))
						.set(CollecttionServicePartSize.column_createDate, new Date());
				if (!sps.save()) {
					log.debug("保存测量尺寸失败");
					throw new RuntimeException("保存测量尺寸失败!");
				}
			}
		}
		// 更新顾客详情本次体重和到店时间

		if (cd != null) {
			cd.set(CustomerDetail.column_nowWeight, cs.getFloat(CollecttionCustomerService.column_weight))
					.set(CustomerDetail.column_toStoreDate, new Date());
			if (!cd.update()) {
				log.debug("更新顾客详情本次体重和到店时间失败");
				throw new RuntimeException("更新顾客详情本次体重和到店时间失败!");
			}
		}
		//保存顾客日常
		ch.set(CustomerHabit.column_serviceID, cs.getStr(CollecttionCustomerService.column_ids))
			.set(CustomerHabit.column_customerID, c.getStr(Customer.column_ids))
			.set(CustomerHabit.column_organIds, orgIds)
		    .set(CustomerHabit.column_gxsj, new Date());
		if(!ch.save())
		{
			log.debug("保存顾客生活日常失败");
			throw new RuntimeException("保存顾客生活日常失败!");
		}
		
		return msg;

	}

	/**
	 * 获取减重计划
	 * 
	 * @param cusIds
	 * @return
	 */
	public Map<String,Object> getDelweight(String cusIds, String date, String orgids) {
		String msg = ConstantRender.render_success_code;
		Map<String, Object>  map=new  HashMap<>();
		List list = new ArrayList<>();
		String sql = getSqlMy(DelWeiTargetSum.sqlId_selByCusAndDate);
		List<DelWeiTargetSum> dtsList = DelWeiTargetSum.dao.find(sql, cusIds, date, date);
		if (dtsList != null && dtsList.size() > 0 && dtsList.size() < 2) {
			Map<String, Object> param = new HashMap<String, Object>();
			param.put("column", DelWeiTarget.column_targetIds);
			String dwtsql = getSqlByBeetl(DelWeiTarget.sqlId_column, param);
			List<DelWeiTarget> dwtList = DelWeiTarget.dao.find(dwtsql, dtsList.get(0).getStr(DelWeiTarget.column_ids));
			if (dwtList != null && dwtList.size() > 0) {
				for (DelWeiTarget dwt : dwtList) {
					Map mm = new HashMap<>();
					mm.put("schedules", dwt.getStr(DelWeiTarget.column_schedule));
					mm.put("starttime", dwt.getDate(DelWeiTarget.column_startTime));
					mm.put("endtime", dwt.getDate(DelWeiTarget.column_endTime));
					mm.put("planner", dwt.getInt(DelWeiTarget.column_planToStoreNum));
					String serSql = getSqlMy(CollecttionCustomerService.sqlId_selByDate);
					List<CollecttionCustomerService> csList = CollecttionCustomerService.dao.find(serSql, cusIds, orgids,
							dwt.getDate(DelWeiTarget.column_startTime).toString(),
							dwt.getDate(DelWeiTarget.column_endTime).toString());
					mm.put("reality", csList.size());
					// 创建一个数值格式化对象
					NumberFormat numberFormat = NumberFormat.getInstance();
					// 设置精确到小数点后2位
					numberFormat.setMaximumFractionDigits(2);
					float wcbl = 0;
					float delweight = 0;
					if (csList != null && csList.size() > 0) {
						wcbl = (float) csList.size() / (float) dwt.getInt(DelWeiTarget.column_planToStoreNum);
						delweight = csList.get(0).getFloat(CollecttionCustomerService.column_weight)
								- csList.get(csList.size() - 1).getFloat(CollecttionCustomerService.column_weight);
					}
					String jzjs = numberFormat.format(delweight / dwt.getFloat(DelWeiTarget.column_delWeiTarget) * 100);
					mm.put("analogy", numberFormat.format(wcbl * 100) + "%");
					mm.put("effect", jzjs + "%");
					list.add(mm);
				}
			}
		}
		if (dtsList.size() > 1) {
			msg = "一个顾客在同时期只能有一个总排期，请检查该顾客减重目标管理排期设置！";
		}
		map.put("msg", msg);
		map.put("delWeightList", list);
		return map;
	}

	/**
	 * 获取减重计划
	 * 
	 * @param cusIds
	 * @return
	 * @throws ParseException
	 */
	public List<CollecttionCustomerService> getDelweiRecord(String orgids, String cusIds, String date) throws ParseException {
		String d="%"+date+"%";
		String sql = getSqlMy(CollecttionCustomerService.sqlId_selByMonth);
		List<CollecttionCustomerService> cs = CollecttionCustomerService.dao.find(sql, cusIds, orgids, d);
		return cs;
	}

	public List<Record> getView(String cUserOrganIds,String name ,String phone ,String hybh) {
		 Map<String, Object> queryParam = new HashMap<String, Object>();
		 queryParam.put("organids", cUserOrganIds);
		 queryParam.put("name", name);
		 queryParam.put("phone", phone);
		 queryParam.put("hybh", hybh);
		 List<Record> lis = find(CollecttionCustomerService.sqlId_selSerByOrganids, queryParam);
		return lis;
	}

	public List<Record> getTodayView(String cUserOrganIds, String name, String phone, String hybh) {
		 Map<String, Object> queryParam = new HashMap<String, Object>();
		 queryParam.put("organids", cUserOrganIds);
		 queryParam.put("name", name);
		 queryParam.put("phone", phone);
		 queryParam.put("hybh", hybh);
		 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		 queryParam.put("today", sdf.format(new Date()));
//		 queryParam.put("today", "2017-10-10");
		 List<Record> lis = find(CollecttionCustomerService.sqlId_selSerTodayByOrganids, queryParam);
		return lis;
	}
	/**今日服务合计功能数据
	 * 
	 * @param cUserOrganIds 机构Ids
	 * @return
	 */
	public Record totaloftodayservice(String cUserOrganIds){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Record record = new Record();
		//到店人数
		String sqloftotalofpeople = "SELECT count(*) AS totalofpeople FROM sb_customer_service AS sbcs WHERE sbcs.organids = ? AND DATE_FORMAT(sbcs.startTime,'%Y-%m-%d')=?";
		//涨秤人数
		String sqloftotalofupweightpeople = "SELECT count(*) AS totalofupweightpeople FROM sb_customer_service AS sbcs WHERE sbcs.organids = ? AND DATE_FORMAT(sbcs.startTime,'%Y-%m-%d')=? AND sbcs.weight-sbcs.lastWeight>0";
		//平秤人数
		String sqloftotalofnoloseweight = "SELECT count(*) AS totalofnoloseweight FROM sb_customer_service AS sbcs WHERE sbcs.organids = ? AND DATE_FORMAT(sbcs.startTime,'%Y-%m-%d')=? AND sbcs.weight-sbcs.lastWeight=0";
		//减秤人数
		String sqloftotalofdownweightpeople = "SELECT count(*) AS totalofdownweightpeople FROM sb_customer_service AS sbcs WHERE sbcs.organids = ? AND DATE_FORMAT(sbcs.startTime,'%Y-%m-%d')=? AND sbcs.weight-sbcs.lastWeight<0";
		//涨秤斤数
		String sqlupweight = "SELECT SUM( sbcs.weight - sbcs.lastWeight ) AS upweight FROM sb_customer_service AS sbcs WHERE sbcs.organids = ? AND DATE_FORMAT(sbcs.startTime, '%Y-%m-%d') = ? AND sbcs.weight - sbcs.lastWeight > 0";
		//掉秤斤数
		String sqldownweight = "SELECT SUM( sbcs.lastWeight - sbcs.weight ) AS downweight FROM sb_customer_service AS sbcs WHERE sbcs.organids = ? AND DATE_FORMAT(sbcs.startTime, '%Y-%m-%d') = ? AND sbcs.weight - sbcs.lastWeight < 0";
		//精护人数
		String sqljinghu = "SELECT count(sbcs.isShaping) AS jinghu FROM sb_customer_service AS sbcs WHERE sbcs.organids = ? AND DATE_FORMAT(sbcs.startTime, '%Y-%m-%d') = ? AND sbcs.isShaping = '1'";
		//巩固人数
		String sqlofgonggu = "SELECT count(*) AS gonggurenshu FROM sb_customer_service AS sbcs WHERE sbcs.organids = ? AND DATE_FORMAT(sbcs.startTime, '%Y-%m-%d') =? AND sbcs.isGg = '1'";
		Record result = Db.findFirst(sqloftotalofpeople,cUserOrganIds,sdf.format(new Date()));
		Record resultupweight = Db.findFirst(sqloftotalofupweightpeople,cUserOrganIds,sdf.format(new Date()));
		Record resultdownweight = Db.findFirst(sqloftotalofdownweightpeople,cUserOrganIds,sdf.format(new Date()));
		Record resultnoloseweight = Db.findFirst(sqloftotalofnoloseweight,cUserOrganIds,sdf.format(new Date()));
		Record upweight = Db.findFirst(sqlupweight,cUserOrganIds,sdf.format(new Date()));
		Record downweight = Db.findFirst(sqldownweight,cUserOrganIds,sdf.format(new Date()));
		Record jinghu = Db.findFirst(sqljinghu,cUserOrganIds,sdf.format(new Date()));
		Record gonggu = Db.findFirst(sqlofgonggu,cUserOrganIds,sdf.format(new Date()));
		record.set("date", sdf.format(new Date()))
			  .set("totalofpeople", result.get("totalofpeople"))
			  .set("totalofupweightpeople",resultupweight.get("totalofupweightpeople"))
			  .set("totalofdownweightpeople", resultdownweight.get("totalofdownweightpeople"))
			  .set("totalofnoloseweight", resultnoloseweight.get("totalofnoloseweight"))
			  .set("upweight", upweight.get("upweight")==null?"0":upweight.get("upweight"))
			  .set("downweight", downweight.get("downweight")==null?"0":downweight.get("downweight"))
			  .set("jinghu", jinghu.get("jinghu"))
			  .set("totalloseweight",(float)Math.round((Float.parseFloat(downweight.get("downweight")==null?"0":downweight.get("downweight").toString())-Float.parseFloat(upweight.get("upweight")==null?"0":upweight.get("upweight").toString()))*10)/10)
//			  .set("proportionforloseweight",(float)Math.round(Float.parseFloat(resultdownweight.get("totalofdownweightpeople").toString())/Float.parseFloat(result.get("totalofpeople").toString())*10000)/100)
//			  .set("proportionforjinghu",(float)Math.round(Float.parseFloat(jinghu.get("jinghu").toString())/Float.parseFloat(result.get("totalofpeople").toString())*10000)/100)
			  .set("gonggurenshu", gonggu.get("gonggurenshu"));
		if(result.get("totalofpeople")=="0"){
			  record.set("proportionforloseweight","0")
			  .set("proportionforjinghu","0");
			
		}else{
			  record.set("proportionforloseweight",(float)Math.round(Float.parseFloat(resultdownweight.get("totalofdownweightpeople").toString())/Float.parseFloat(result.get("totalofpeople").toString())*10000)/100)
			  .set("proportionforjinghu",(float)Math.round(Float.parseFloat(jinghu.get("jinghu").toString())/Float.parseFloat(result.get("totalofpeople").toString())*10000)/100);

		}
		return record;
	}

	public List<Record> getNearStaWeight(String cUserOrganIds) {
		 Map<String, Object> queryParam = new HashMap<String, Object>();
		 queryParam.put("organIds", cUserOrganIds);
		 List<Record> lis = find(CollecttionCustomerService.sqlId_nearStaWeight, queryParam);
		return lis;
	}

}
